/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.yuhanginfo.modules.sys.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.yuhanginfo.common.config.Global;
import com.yuhanginfo.common.persistence.Page;
import com.yuhanginfo.common.web.BaseController;
import com.yuhanginfo.common.utils.StringUtils;
import com.yuhanginfo.modules.sys.entity.GoodsCombo;
import com.yuhanginfo.modules.sys.service.GoodsComboService;

/**
 * 商品套餐上下架Controller
 * @author lvls
 * @version 2017-11-15
 */
@Controller
@RequestMapping(value = "${adminPath}/sys/goodsComboUpDown")
public class GoodsComboUpDownController extends BaseController {

	@Autowired
	private GoodsComboService goodsComboService;
	
	private static final  String REDIRECT = "redirect:";
	
	private static final  String LINK = "/sys/goodsComboUpDown/?repage";
	@ModelAttribute
	public GoodsCombo get(@RequestParam(required=false) String id) {
		GoodsCombo entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = goodsComboService.get(id);
		}
		if (entity == null){
			entity = new GoodsCombo();
		}
		return entity;
	}
	
	@RequiresPermissions("sys:goodsComboUpDown:view")
	@RequestMapping(value = {"list", ""})
	public String list(GoodsCombo goodsCombo, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<GoodsCombo> page = goodsComboService.findPage(new Page<GoodsCombo>(request, response), goodsCombo); 
		model.addAttribute("page", page);
		return "modules/sys/goodsComboUpDown/goodsComboUpDownList";
	}
	
	@RequiresPermissions("sys:goodsComboUpDown:edit")
	@RequestMapping(value = "goodsComboDown")
	public String goodsComboDown(GoodsCombo goodsCombo, RedirectAttributes redirectAttributes) {
		goodsComboService.goodsComboDown(goodsCombo);
		addMessage(redirectAttributes, "下架成功");
		return REDIRECT+Global.getAdminPath()+LINK;
	}
	
	@RequiresPermissions("sys:goodsComboUpDown:edit")
	@RequestMapping(value = "goodsComboUp")
	public String goodsComboUp(GoodsCombo goodsCombo,String storeId, RedirectAttributes redirectAttributes) {
		goodsComboService.goodsComboUp(goodsCombo,storeId);
		addMessage(redirectAttributes, "上架成功");
		return REDIRECT+Global.getAdminPath()+LINK;
	}
	
	@RequiresPermissions("sys:goodsComboUpDown:edit")
	@RequestMapping(value = "goodsComboChange")
	public String goodsComboChange(GoodsCombo goodsCombo,String storeId, RedirectAttributes redirectAttributes) {
		goodsComboService.goodsComboChange(goodsCombo,storeId);
		addMessage(redirectAttributes, "调整成功");
		return REDIRECT+Global.getAdminPath()+LINK;
	}
	
	@RequiresPermissions("sys:goodsComboUpDown:edit")
	@RequestMapping(value = "selectStoreList")
	public String selectAllStoreListByType(GoodsCombo goodsCombo,HttpServletRequest request, HttpServletResponse response, Model model) {
		model.addAllAttributes(goodsComboService.getGoodsComboStore(goodsCombo));
		return "modules/sys/goodsComboUpDown/tagStoreselectForGoodsUpDown";
	}

}